<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <base href="${pageContext.request.contextPath}/">
    <title>Title</title>
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <!-- bootstrap-table样式文件 -->
    <link rel="stylesheet" href="bootstrap-table/bootstrap-table.min.css">
    <script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
    <!-- bootstrap-table的js文件 -->
    <script type="text/javascript" src="bootstrap-table/bootstrap-table.min.js"></script>
    <!-- bootstrap-table的语言包 -->
    <script type="text/javascript" src="bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>
    <script type="text/javascript">
        $(function () {
            initTable();

        });
        //初始化表格
        function initTable() {
            $("#tab").bootstrapTable({
                //表格高度
                height: 560,
                // theadClasses: ".thead-dark",
                //本地的数据
                // data:[
                //     {"id":1001,"name":"tom","gender":"0"},
                //     {"id":1002,"name":"jerry","gender":"1"},
                //     {"id":1003,"name":"zhangsan","gender":"0"},
                //     {"id":1004,"name":"lisi","gender":"1"}
                // ],
                //远程访问地址
                url: "section/list",
                //请求方法
                method: "get",
                //异步提交时向后台提交的请求参数
                queryParams: function(params){
                    params["divName"]=$("#divName").val().trim();
                    return params;
                 },
                //修改分页组件向后台提交数据
                queryParamsType: "",
                //开启分页
                pagination: true,
                //设置服务器分页
                sidePagination: "server",
                //每页条数
                pageSize: 10,
                //用户设置的每页条数列表
                pageList: [10,20,30,50],
                //上一页和下一页文本
                paginationPreText: "上一页",
                paginationNextText: "下一页",
                //刷新按钮
                showRefresh: true,
                //点击选中
                clickToSelect: true,
                //单选
                singleSelect: false,
                //工具栏
                toolbar: "#toolbar",
                //表格中的列描述
                columns: [
                    {
                        //表格第一列为复选框
                        checkbox: true
                    },{
                        //表示json字符串中的属性名称
                        /*
                            "[{"id":1001,"name":"tom","gender":"0"},{"id":1002,"name":"jerry","gender":"1"}]"
                         */
                        field: "id",
                        //隐藏列
                        visible: false
                    },{
                        //表头中的文本
                        field: "orgId",
                        //设置表头的对齐方式
                        title: "机构id",
                        halign: "center"
                    },{
                        field: "orgNo",
                        title: "机构编码",
                        halign: "center"
                    },{
                        field: "divCode",
                        title: "科室编码",
                        halign: "center"
                    },{
                        field: "divNameCode",
                        title: "科室名称编码",
                        halign: "center",
                    },{
                        field: "divName",
                        title: "科室名称代码",
                        halign: "center",
                    },{
                        field: "ifSub",
                        title: "是否为分所",
                        halign: "center",
                        formatter: function (value) {
                            var ifSub = ["是","否"];
                            return ifSub[value];
                        }
                    },{
                        field: "dutyTel",
                        title: "电话号码",
                        halign: "center"
                    },{
                        field: "fax",
                        title: "传真号码",
                        halign: "center",

                    },{
                        field: "divRoomNo",
                        title: "门号",
                        halign: "center"
                    },{
                        field: "exetype",
                        title: "行政类别",
                        halign: "center"
                    }
                ]
            });
        }

        function insert() {
            $.post("organization/list",null,function (res) {
                var orgName;
                var orgNo;
                $.each(res.rows,function () {
                    orgName += "<option value='" +this.id+"'>"+ this.orgname + "</option>";
                    orgNo += "<option value='" +this.orgNo+"'>" + this.orgNo +"</option>";
                });
                $("#in_orgId").html(orgName);
                $("#in_orgNo").html(orgNo);
                $("#insert_win").modal("show");
            })
        }
        function doInsert(){
            $.post("section/add",{
                id:$("#in_id").val().trim(),
                orgId : $("#in_orgId").val().trim(),
                orgCode : $("#in_orgCode").val().trim(),
                orgNo : $("#in_orgNo").val().trim(),
                divCode : $("#in_divCode").val().trim(),
                divNameCode : $("#in_divNameCode").val(),
                divName : $("#in_divName").val().trim(),
                ifSub : $("#in_ifSub").val().trim(),
                dutyTel : $("#in_dutyTel").val().trim(),
                fax : $("#in_fax").val().trim(),
                divRoomNo : $("#in_divRoomNo").val().trim(),
                exetype : $("#in_exetype").val().trim()
            },function (res) {
                if(res.status==200){
                    alert("新增成功");
                    $("#insert_win").modal("hide");
                    $("#tab").bootstrapTable("refresh");
                    $("#insert_form")[0].reset();
                }
            });
        }

        function doPreUpdate() {
            var rows = $("#tab").bootstrapTable("getSelections");
            if(rows.length==0){
                alert("请选中一条要修改的数据");
            }else if(rows.length>1){
                alert("只能修改一条数据");
            }else{
                $.get("section/get/"+rows[0].id,null,function (res) {
                    $("#up_id").val(res.data.id);
                    $("#up_orgId").val(res.data.orgId);
                    $("#up_orgCode").val(res.data.orgCode);
                    $("#up_orgNo").val(res.data.orgNo);
                    $("#up_divCode").val(res.data.divCode);
                    $("#up_divNameCode").val(res.data.divNameCode);
                    $("#up_divName").val(res.data.divName);
                    $("#up_ifSub").val(res.data.ifSub);
                    $("#up_dutyTel").val(res.data.dutyTel);
                    $("#up_fax").val(res.data.fax);
                    $("#up_divRoomNo").val(res.data.divRoomNo);
                    $("#up_exetype").val(res.data.exetype);
                    $("#update_win").modal("show");
                });
            }
        }

        function doUpdate(){
            $.post("section/update",{
                id : $("#up_id").val(),
                orgId  : $("#up_orgId ").val().trim(),
                orgNo : $("#up_orgNo").val().trim(),
                divCode : $("#up_divCode").val(),
                divNameCode : $("#up_divNameCode").val().trim(),
                divName : $("#up_divName").val().trim(),
                ifSub : $("#up_ifSub").val().trim(),
                dutyTel : $("#up_dutyTel").val().trim(),
                fax : $("#up_fax").val(),
                divRoomNo : $("#up_divRoomNo").val().trim(),
                exetype : $("#up_exetype").val().trim()
            },function (res) {
                if(res.status==200){
                    alert("修改成功");
                    $("#update_win").modal("hide");
                    $("#tab").bootstrapTable("refresh");
                    $("#update_form")[0].reset();
                }
            });
        }

        function doDelete() {
            var rows = $("#tab").bootstrapTable("getSelections");
            if(rows.length==0){
                alert("请选中一条要删除的数据");
            }else{
                if(!confirm("确定删除吗?")) return;
                var ids = [];
                $.each(rows, function () {
                    ids.push(this.id);
                });
                // alert(ids);
                $.get("section/removeBatch",{ids : ids},function (res) {
                    if(res.status==200){
                        alert("删除成功");
                        $("#tab").bootstrapTable("refresh");
                    }
                });
            }
        }

    </script>
</head>
<body>
    <!--=======================路径导航=========================-->
    <ol class="breadcrumb">
        <li>主页</li>
        <li>系统管理</li>
        <li class="active">组织机构</li>
    </ol>
    <!--=======================路径导航.end=========================-->
    <!--=======================页面主体=========================-->
    <div class="panel-body">
        <form id="toolbar" class="form-inline">
            <div class="btn-group">
                <button type="button" class="btn btn-default" onclick="insert()">新增</button>
                <button type="button" class="btn btn-success" onclick="doPreUpdate()">修改</button>
                <button type="button" class="btn btn-danger" onclick="doDelete()">删除</button>
                <button type="button" class="btn btn-primary" onclick="changeStatus()">切换状态</button>
                <button type="button" class="btn btn-info" onclick="preSetRole()">设置角色</button>
            </div>
            <div class="form-group">
                <input type="text" class="form-control" id="divName" placeholder="科室名称代码">
            </div>
            <div class="form-group">
                <select id="status" class="form-control">
                    <option value="">--用户状态--</option>
                    <option value="0">正常</option>
                    <option value="1">停用</option>
                </select>
            </div>
            <div class="btn-group">
                <button type="button" class="btn btn-default" onclick="$('#tab').bootstrapTable('refresh')">搜索</button>
                <button type="button" class="btn btn-default" onclick="$('#toolbar')[0].reset();$('#tab').bootstrapTable('refresh');">清空</button>
            </div>
        </form>
        <table id="tab" class="table table-bordered table-hover table-striped"></table>
    </div>
    <!--=======================页面主体.end=========================-->
    <!--=======================新增窗体=========================-->
    <div id="insert_win" class="modal fade"  tabindex="-1" role="dialog">
        <div class="modal-dialog modal-sm" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">新增科室</h4>
                </div>
                <div class="modal-body">
                    <form id="insert_form">
                        <input type="hidden" id="in_id" >
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">机构名称</div>
                                <select id="in_orgId" class="form-control" >
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">内部编码</div>
                                <select id="in_orgNo" class="form-control">
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">机构代码</div>
                                <input type="text" id="in_orgCode" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">科室编码</div>
                                <input type="text" id="in_divCode" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">科室名称编码</div>
                                <input type="text" id="in_divNameCode" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">科室名称</div>
                                <input type="text" id="in_divName" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">是否为分所</div>
                                <%--<input type="text" id="in_orgLevel" class="form-control">--%>
                                <select id="in_ifSub" class="form-control">
                                    <option value="0">分所</option>
                                    <option value="1">不是</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">电话号码</div>
                                <input type="text" id="in_dutyTel" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">传真号码</div>
                                <input type="text" id="in_fax" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">门号</div>
                                <input type="text" id="in_divRoomNo" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">行政类别</div>
                                <input type="text" id="in_exetype" class="form-control">
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" onclick="doInsert()">确定</button>
                </div>
            </div>
        </div>
    </div>
    <!--=======================新增窗体.end=========================-->
    <!--=======================修改窗体=========================-->
    <div id="update_win" class="modal fade" tabindex="-1" role="dialog">
        <div class="modal-dialog modal-sm" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">修改科室</h4>
                </div>
                <div class="modal-body">
                    <form id="update_form">
                        <input type="hidden" id="up_id">
                        <input type="hidden" id="up_updater" value="lisi">
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">机构id</div>
                                <input type="text" id="up_orgId" class="form-control" >
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">内部编码</div>
                                <input type="text" id="up_orgNo" class="form-control" >
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">科室编码</div>
                                <input type="text" id="up_divCode" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">科室名称编码</div>
                                <input type="text" id="up_divNameCode" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">科室名称代码</div>
                                <input type="text" id="up_divName" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">是否分所</div>
                                <select id="up_ifSub" class="form-control">
                                    <option value="0">分所</option>
                                    <option value="1">不是</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">电话号码</div>
                                <input type="text" id="up_dutyTel" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">传真号码</div>
                                <input type="text" id="up_fax" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">门号</div>
                                <input type="text" id="up_divRoomNo" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">行政类别</div>
                                <input type="text" id="up_exetype" class="form-control">
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" onclick="doUpdate()">确定</button>
                </div>
            </div>
        </div>
    </div>
    <!--=======================修改窗体.end=========================-->
</body>
</html>
